* Table 5
local table "Table5"
use "./data/publications.dta", clear
createvarspub
addcuraff
keep if (abs=="4" | abs=="4*" | cnrs=="1" | cnrs=="1e" | cnrs=="1g")
local nrows=32
qui putexcel set "./tables/tables.xlsx", sheet("`table'") modify
bys person_id: egen firstyear=min(year)
keep if year>1999
gen shareart=1/naut
keep if national==1|portnat==1
collapse (count) article (sum) shareart, by(person_id name curaff firstyear phdyear)
gsort - article name
list name curaff article  in 1/`nrows'
* output to excel
mkmat article in 1/`nrows', mat(P1)
mkmat shareart in 1/`nrows', mat(P2)
mkmat firstyear phdyear in 1/`nrows', mat(P3)
qui putexcel A1=("Name")
qui putexcel B1=("Current Affiliation")
forval i=1/`nrows' {
local j=`i'+1
local na=name[`i']
local af=curaff[`i']
qui putexcel A`j'="`na'"
qui putexcel B`j'="`af'"
}
qui putexcel C1=("Pubs")
qui putexcel D1=("Adj")
qui putexcel E1=("1st")
qui putexcel F1=("Phd")
qui putexcel C2=matrix(P1)
qui putexcel D2=matrix(P2), nformat(#.0)
qui putexcel E2=matrix(P3)
